﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderManage
{
    public struct Date
    {
        public int year;
        public int month;
        public int day;
        public Date(int y,int m,int d) { year = y;month = m;day = d; }
        public override string ToString()
        {
            string s = "";
            return s + year + "-"+month+"-"+day;
        }
    }
    public class Order:IComparable
    {
        public string orderId { get; set; }
        public OrderDetails orderDetails { get; set; }
        public Customer customer { get; set; }
        public Date orderDate { get; set; }
        private double money;
        public Order(string id,string customerName,string date)
        {
            orderId = id;
            orderDetails = new OrderDetails();
            customer = new Customer(customerName);
            string y = date.Substring(0,date.IndexOf("-"));
            string m = date.Substring(date.IndexOf("-")+1, date.LastIndexOf("-")- date.IndexOf("-")-1);
            string d = date.Substring(date.LastIndexOf("-")+1,date.Length-1- date.LastIndexOf("-"));
            orderDate = new Date(int.Parse(y), int.Parse(m), int.Parse(d));
            money = 0;
        }
        public double GetMoney()
        {
            money = 0;
            for(int i = 0; i < orderDetails.count; i++)
            {
                money += orderDetails.goods[i].price * orderDetails.numbers[i];
            }
            return money;
        }

        public int CompareTo(object obj)
        {
            if (!(obj is Order))
            {
                throw new NotImplementedException();
            }
            Order rec = (Order)obj;
            return this.orderId.CompareTo(rec.orderId);
        }
        public override string ToString()
        {
            string order = "";
            order += "Order ID:" +orderId+"\n";
            order +="Customer:"+customer+"\n";
            order += "Order Date:" + orderDate + "\n";
            order +="Details:\n"+orderDetails;
            order += "sum money:" + GetMoney();
            return order;
        }
        public override bool Equals(object obj)
        {
            Order o = obj as Order;
            return o!=null&&o.orderId.Equals(orderId)&&o.customer.Equals(customer)&&o.orderDetails.Equals(orderDetails)&&o.GetMoney()== GetMoney();
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
